#
# Author: pepone.onrez@gmail.com
#


SET ( COPY_FILE cp -v )

#
# Generate rules for buil slice files.
#
MACRO ( YDRA_LEXER_RULES LEXER_CPP_GENERATED_SOURCE )

    SET( LEXER_GRAMMAR_FILE ${ARGN} )

    STRING( REGEX REPLACE "\\.g" .cpp LEXER_SOURCE_BASENAME "${LEXER_GRAMMAR_FILE}" )

    SET( LEXER_SOURCE_TARGET ${PROJECT_SOURCE_DIR}/src/generated/${LEXER_SOURCE_BASENAME} )

    MESSAGE ( STATUS " Lexer source: ${LEXER_SOURCE_BASENAME} " )
    MESSAGE ( STATUS " Lexer source target: ${LEXER_SOURCE_TARGET} " )

    SET(LEXER_SOURCE_PATH ${PROJECT_SOURCE_DIR}/antlr/${LEXER_GRAMMAR_FILE} )

    ADD_CUSTOM_COMMAND(
        OUTPUT ${LEXER_SOURCE_BASENAME}
        COMMAND ${COPY_FILE} ${LEXER_SOURCE_PATH} ${LEXER_SOURCE_BASENAME}
        DEPENDS ${LEXER_SOURCE_PATH}
        COMMENT "generating ${LEXER_SOURCE_BASENAME} ")

    ADD_CUSTOM_COMMAND(
        OUTPUT ${LEXER_SOURCE_TARGET}
        COMMAND ${COPY_FILE} ${LEXER_SOURCE_BASENAME} ${LEXER_SOURCE_TARGET}
        DEPENDS ${LEXER_SOURCE_BASENAME}
        COMMENT "generating third step ${LEXER_SOURCE_TARGET}")

    SET( LEXER_CPP_GENERATED_SOURCE ${LEXER_SOURCE_TARGET} )

ENDMACRO ( YDRA_LEXER_RULES LEXER_CPP_GENERATED_SOURCE )
